﻿@{
    ViewBag.Title = "PostIndex";
    Layout = "~/Views/Shared/_Layout.cshtml";
}
@section Head
{
    @Html.Css("EditForm", "RightSeparateModule", "dp")
    @Html.Js("datepicker")

    <script type="text/javascript">

        $(function () {
            var mainheight = document.documentElement.clientHeight;
            var mainWidth = document.documentElement.clientWidth - 10;
            var gh = mainheight - 130;
            var option = {
                height: gh,
                width: mainWidth,
                url: '@Url.Action("GetPostList")',
                colModel: [
                     { display: 'ID', name: 'ID', width: 60, sortable: false, align: 'left', hide: true, iskey: true },
                     { display: '工种', name: 'PostId', width: 160, sortable: false, hide: false, align: 'left' },
			         { display: '物品名称', name: 'ArticleId', width: 80, sortable: false, hide: false, align: 'left' },
                     { display: '领取时间', name: 'RuleId', width: 100, sortable: false, hide: false, align: 'left' },
                     { display: '领取数量', name: 'GiveCount', width: 80, sortable: false, hide: false, align: 'left' }

                  	],
                buttons: [
                            { name: 'Add', displayname: "新建", title: "新建", bclass: 'add', onpress: toolbarItem_onclick },
                            { name: 'Edit', displayname: "修改", title: "编辑", bclass: 'edit', onpress: toolbarItem_onclick },
                            { name: 'Delete', displayname: "删除", title: "删除", bclass: 'delete', onpress: toolbarItem_onclick },
                            { separator: true }
                         ],
                singleselected: false,
                sortname: "Sequence",
                sortorder: "asc",
                title: false,
                usepager: true,
                page: 1,
                rp: 20,
                rpoption: [10, 15, 20],
                showcheckbox: true,
                selectedonclick: true, //点击行是否选中
                rowbinddata: true
            };
            var instockgrid = $("#postList").flexigrid(option);
            //新增，删除，修改
            function toolbarItem_onclick(cmd, grid) {
                if (cmd == "Add") {
                    OpenModelWindow('@Url.Action("AddPost")', { width: 520, height: 210, caption: "劳防工种（岗位）添加",
                        onclose: refresh
                    });
                }
                else if (cmd == 'Edit') {
                    var ids = "";
                    if ($('.trSelected', grid).length == 0 || $('.trSelected', grid).length > 1) {
                        showLoadingMsg("请选择一行数据进行编辑", { left: 300, top: 2 }, true, 3000);
                        return false;
                    }
                    else {
                        var items = $('.trSelected', grid);
                        for (i = 0; i < items.length; i++) {
                            if (i == items.length - 1) {
                                ids += items[i].id.substr(3);
                            } else {
                                ids += items[i].id.substr(3) + ", ";
                            } //if 
                        } //for
                    }
                    OpenModelWindow('@Url.Action("AddPost")?id=' + ids,
                        {
                            width: 520,
                            height: 210,
                            caption: "维护劳防工种(岗位)",
                            onclose: refresh
                        });
                }

                else if (cmd == 'Delete') {
                    if ($('.trSelected', grid).length == 0) {
                        showLoadingMsg("请选择要删除的行", { left: 300, top: 2 }, true, 3000);
                        return false;
                    } else {
                        if (confirm("确定要删除吗?")) {
                            var rowcount = 0;
                            var items = $('.trSelected', grid);
                            for (var i = 0; i < items.length; i++) {
                                var id = items[i].id.substr(3);
                                $.ajax({
                                    url: '@Url.Action("Delete")',
                                    type: "POST",
                                    data: { id: id },
                                    async: false,
                                    success: function (data) {
                                        if (data) {
                                            rowcount = rowcount + data;
                                        }
                                    },
                                    error: function () {
                                    }
                                });
                            } //for
                            showLoadingMsg("共有" + rowcount.toString() + "个劳防工种(岗位)被删除!", { left: 400, top: 6 }, true, 3000);
                            refresh();
                        }
                    }
                }
            } // end of toolbarItem_onclick
            $("#btnQuery").bind("click", function () {
                var no = $('#PostName').val() == null ? "" : $('#PostName').val();
                option.query = no;
                option.newp = 0;
                $('#postList').flexOptions(option).flexReload();
            });
            function refresh() {
                $("#postList").flexOptions(option).flexReload();
            }

        });
    </script>
}
<div id="container">
    <div id="mainContent">
        <div id="title" class="title">
          @Html.TextBox("PostName")
     <input type="button" value="查询" id="btnQuery" style="width: 62px; height: 23px;" />
          </div>
      
        <table id="postList" style="display: none;">
        </table>
    </div>
</div>



